/*
 * @Copyright: Copyright (c) 2019
 * @Author: caizhijun
 * @Version: 1.0
 * @Date: 2018-06-27 17:22:34
 */
cc.Class({
    extends: cc.Component,

    properties: {
       pickRadius:0
    },  
   onload:function() {
    },
    getPlayerDistance:function(){
        var playerPos=this.game.player.getPosition();
        // var dist=cc.pDistance(this.node.position,playerPos);
        var dist = this.node.position.sub(playerPos).mag();
        return dist;
    },
    onPick:function(){
        var pos=this.node.getPosition();
        this.game.gainScore(pos);
        this.game.despawnStar(this.node);
    },
    update:function(dt){
        if(this.getPlayerDistance()<this.pickRadius){
            this.onPick();
            return;
        }
        var opacityRatio=1-this.game.timer/this.game.starDuration;
        var minOpacity=50;
        this.node.opacity=minOpacity+Math.floor(opacityRatio*(255-minOpacity));
    }
});
